"""
---------------------------------------------------------------------
- File: schemas.py
- Date: 2025/9/19
- Author: yangzhide
- Email: xxzjyzd@126.com
- Description:
---------------------------------------------------------------------
"""

from datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, field_serializer


class RoleList(BaseModel):
    """角色列表模型"""

    role_id: int = Field(description="角色ID")
    role_name: str = Field(description="角色名称")


class UserBase(BaseModel):
    """系统用户列表输入模型"""

    user_no: str = Field(description="登录编号")
    user_name: str = Field(description="姓名")
    nick_name: str = Field(description="昵称")
    user_gender: str = Field(description="性别")
    user_email: str = Field(description="邮箱")
    user_phone: str = Field(description="手机")
    role_list: list[RoleList] = Field(default_factory=list, description="角色列表")
    status: bool = Field(False, description="状态")


class UserIn(UserBase):
    """系统用户列表输入模型"""

    password: str = Field("gzbs", description="密码")


class UserListOut(UserBase):
    """系统用户列表输出模型"""

    id: int = Field(description="ID")
    create_time: datetime = Field(description="创建时间")
    update_time: datetime = Field(description="更新时间")

    # 开启属性读取模式
    model_config = ConfigDict(from_attributes=True)

    @field_serializer("create_time", "update_time")
    def serialize_time(self, time: datetime):
        return time.strftime("%Y-%m-%d %H:%M:%S")


class UserPwdIn(BaseModel):
    """系统用户密码输入模型"""

    password: int | str = Field(description="用户ID")


#     哈希密码
